package com.ahdms.es.gm.v1;

import org.bouncycastle.asn1.*;

import java.util.Enumeration;

/**
 * 印章签名信息中待签名数据的格式
 *
 * @author Administrator
 */
public class TBS_Seal extends ASN1Object {
    /**
     * 印章信息
     */
    private SES_SealInfo sealInfo;
    /**
     * 制章人证书
     */
    private ASN1OctetString cert;
    /**
     * 签名算法标识
     */
    private ASN1ObjectIdentifier signatureAlgorithm;

    public static TBS_Seal getInstance(Object o) {
        if (o instanceof TBS_Seal) {
            return (TBS_Seal) o;
        } else if (o != null) {
            return new TBS_Seal(ASN1Sequence.getInstance(o));
        }
        throw new IllegalArgumentException("unknown object in factory: " + o.getClass().getName());
    }

    public TBS_Seal(SES_SealInfo sealInfo, ASN1OctetString cert, ASN1ObjectIdentifier signatureAlgorithm) {
        super();
        this.sealInfo = sealInfo;
        this.cert = cert;
        this.signatureAlgorithm = signatureAlgorithm;
    }

    public TBS_Seal(ASN1Sequence seq) {
        Enumeration e = seq.getObjects();
        sealInfo = SES_SealInfo.getInstance(e.nextElement());
        cert = (DEROctetString) (e.nextElement());
        signatureAlgorithm = ASN1ObjectIdentifier.getInstance(e.nextElement());
    }

    @Override
    public ASN1Primitive toASN1Primitive() {
        ASN1EncodableVector v = new ASN1EncodableVector();
        v.add(sealInfo);
        v.add(cert);
        v.add(signatureAlgorithm);
        return new DERSequence(v);
    }

    public SES_SealInfo getSealInfo() {
        return sealInfo;
    }

    public void setSealInfo(SES_SealInfo sealInfo) {
        this.sealInfo = sealInfo;
    }

    public ASN1OctetString getCert() {
        return cert;
    }

    public void setCert(DEROctetString cert) {
        this.cert = cert;
    }

    public ASN1ObjectIdentifier getSignatureAlgorithm() {
        return signatureAlgorithm;
    }

    public void setSignatureAlgorithm(ASN1ObjectIdentifier signatureAlgorithm) {
        this.signatureAlgorithm = signatureAlgorithm;
    }

}
